package com.tech.controller;


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


/**
 * @Description:
 * @Author: zl
 * @Date: 2019/6/18 18:13
 */
@RestController
@RequestMapping("/login/a")
public class LoginTestController {


    //处理登录
    @RequestMapping(value = "/loginUser")
    @ResponseBody
    public ResponseData login(@RequestParam("email") String email,@RequestParam("password") String password) {
        Login login = new Login();
        login.setEmail(email);
        login.setPassword(password);
        ResponseData responseData = ResponseData.ok();
        //先到数据库验证
        Integer loginId = 1001;
        if (null != loginId) {
            login.setId(loginId);
            //给用户jwt加密生成token
            String token = JWT.sign(login, 60L * 1000L * 30L);
            //封装成对象返回给客户端
            responseData.putDataValue("loginId", login.getId());
            responseData.putDataValue("token", token);
        } else {
            responseData = ResponseData.customerError();
        }
        System.out.println("111111111111");
        return responseData;
    }
}
